@echo off
chcp 65001 >nul

REM 停止所有正在运行的Python和Nginx进程
echo 停止所有相关进程...
taskkill /f /im python.exe >nul 2>&1
taskkill /f /im nginx.exe >nul 2>&1

REM 等待进程停止
timeout /t 2 /nobreak >nul

REM 启动3个应用实例
start "App Instance 1" python main.py --port 8001
start "App Instance 2" python main.py --port 8002
start "App Instance 3" python main.py --port 8003

REM 启动Nginx
echo 启动Nginx负载均衡...
start "Nginx" nginx -c f:\bjhsp\nginx.conf

REM 等待服务启动
timeout /t 5 /nobreak >nul

REM 检查服务状态
netstat -ano | findstr :8001 >nul
if %ERRORLEVEL% EQU 0 (
    echo 应用实例1在端口8001启动成功
) else (
    echo 应用实例1在端口8001启动失败
)

netstat -ano | findstr :8002 >nul
if %ERRORLEVEL% EQU 0 (
    echo 应用实例2在端口8002启动成功
) else (
    echo 应用实例2在端口8002启动失败
)

netstat -ano | findstr :8003 >nul
if %ERRORLEVEL% EQU 0 (
    echo 应用实例3在端口8003启动成功
) else (
    echo 应用实例3在端口8003启动失败
)

netstat -ano | findstr :80 >nul
if %ERRORLEVEL% EQU 0 (
    echo Nginx在端口80启动成功
) else (
    echo Nginx在端口80启动失败
)

echo 访问地址:
echo - 应用实例1: http://localhost:8001
echo - 应用实例2: http://localhost:8002
echo - 应用实例3: http://localhost:8003
echo - Nginx负载均衡: http://localhost

REM 打开浏览器访问负载均衡地址
start http://localhost